package com.beardedhen.harmonybootstrap;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.DirectionalLayout;
import ohos.app.Context;

/**
 * This is a base class that provies methods to get updates when a view is removed or added or rotated and contains abstract methods for the set up of the class.
 *

 * @see BootstrapButtonGroup
 */
abstract class BootstrapGroup extends DirectionalLayout {

    public BootstrapGroup(Context context) {
        super(context);
        initialise(null);
    }

    public BootstrapGroup(Context context, AttrSet attrs) {
        super(context, attrs);
        initialise(attrs);
    }

    public BootstrapGroup(Context context, AttrSet attrs, String defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initialise(attrs);
    }

    protected abstract void initialise(AttrSet attrs);

    @Override
    public void setOrientation(int orientation) {
        super.setOrientation(orientation);
        updateBootstrapGroup();
    }

    protected abstract void updateBootstrapGroup();


    protected abstract void onBootstrapViewAdded();

    protected abstract void onBootstrapViewRemoved();
    @Override
    public void addComponent(Component child, int index, ComponentContainer.LayoutConfig params) {
        super.addComponent(child, index, params);
        onBootstrapViewAdded();
    }

    @Override
    public void addComponent(Component childComponent) {
        super.addComponent(childComponent);
        onBootstrapViewAdded();
    }

    @Override
    public void addComponent(Component childComponent, int width, int height) {
        super.addComponent(childComponent, width, height);
        onBootstrapViewAdded();
    }

    @Override
    public void addComponent(Component childComponent, int index) {
        super.addComponent(childComponent, index);
        onBootstrapViewAdded();
    }

    @Override
    public void removeAllComponents() {
        super.removeAllComponents();
        onBootstrapViewRemoved();
    }

    @Override
    public void removeComponent(Component component) {
        super.removeComponent(component);
        onBootstrapViewRemoved();
    }

    @Override
    public void removeComponentAt(int index) {
        super.removeComponentAt(index);
        onBootstrapViewRemoved();
    }

    @Override
    public void removeComponentById(int id) {
        super.removeComponentById(id);
        onBootstrapViewRemoved();
    }

    @Override
    public void removeComponents(int start, int count) {
        super.removeComponents(start, count);
        onBootstrapViewRemoved();
    }
}
